/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.reddys.rad.inventory.service;

import com.reddys.rad.inventory.db.Product;
import com.reddys.rad.inventory.db.Stock;
import static com.reddys.rad.inventory.service.StockMovementHistoryService.em;
import com.reddys.rad.inventory.utils.EntityManagerImpl;
import java.util.Iterator;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.Query;

/**
 *
 * @author REDDYS
 */
public class StockManagementService {
         static EntityManager em;
  
    public List getStockDetails() {

        em = EntityManagerImpl.getEntityManager();
        Query query=em.createNamedQuery("Stock.findAll");
          List list= (List) query.getResultList();
          Iterator iter = list.iterator();
          while(iter.hasNext()){
              Stock stock = (Stock) iter.next();
              Query queryProduct=em.createNamedQuery("Product.findByProductId");
              queryProduct.setParameter("productId", stock.getProductId());
              List productList= (List) queryProduct.getResultList();
              if(productList.size()>0){
                  Product product  = (Product) productList.get(0);
                  stock.setProductCategory(product.getProductCategory());
                  stock.setProductDescription(product.getProductDescription());
              }
           }
        return list;
    }

    
}
